//
//  FBBaseViewController.m
//  FindBook
//
//  Created by zhaoxu_liu on 13-11-1.
//  Copyright (c) 2013年 lzx. All rights reserved.
//

#import "FBBaseViewController.h"
#import "UIViewController+REFrostedViewController.h"

NSString * const FBLOADBOOKSNOTIFICATION = @"FBLOADBOOKSNOTIFICATION";

@interface FBBaseViewController ()
{
    UIPanGestureRecognizer *_panGestureRecognizer;
}

@end

@implementation FBBaseViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    _panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panGestureRecognized:)];
    [self.view addGestureRecognizer:_panGestureRecognizer];
	// Do any additional setup after loading the view.
}

- (void)removePanGesture
{
    [self.view removeGestureRecognizer:_panGestureRecognizer];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)showMenu
{
    [self.frostedViewController presentMenuViewController];
}

#pragma mark -
#pragma mark Gesture recognizer

- (void)panGestureRecognized:(UIPanGestureRecognizer *)sender
{
    [self.frostedViewController panGestureRecognized:sender];
}


#pragma mark - RYCHTTPRequestModelDelegate
- (void)didHTTPRequestModelFinished:(RYCHTTPRequestModel*)aModel
{
    [self hideWaiting];
    [super didHTTPRequestModelFinished:aModel];
}

- (void)didHTTPRequestModelFailed:(RYCHTTPRequestModel*)aModel
{
    [self hideWaiting];
    [super didHTTPRequestModelFailed:aModel];
}


- (void)showWaiting:(BOOL)lock
{
    if (lock)
    {
        [[UIApplication sharedApplication].keyWindow showHUD];
        [UIApplication sharedApplication].keyWindow.userInteractionEnabled = NO;
    }
    else
    {
        [self.view startWaiting];
    }
}

- (void)hideWaiting
{
    [[UIApplication sharedApplication].keyWindow hideHUD];
    [UIApplication sharedApplication].keyWindow.userInteractionEnabled = YES;
    [self.view stopWaiting];
}

@end
